package servlet;

import service.UserService;
import userDao.GetUserImp;
import userDao.Student;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "DeleteStudent",urlPatterns = "/deleteStudent")
public class DeleteStudent extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        String name = request.getParameter("name");
        Student student = new Student(Integer.parseInt(id),name);
        GetUserImp getUserImp = new GetUserImp();
        int i = getUserImp.deleteStudent(student);
        UserService userService = new UserService();
        List<Student> students = userService.getStudents();
        request.getSession().setAttribute("students",students);
        System.out.println("受影响行数为：" + i);
        RequestDispatcher rd = request.getRequestDispatcher("studentManage.jsp");
        rd.forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
